557B - Pasha and Tea - CodeForces Solution


constructive algorithms implementation math sortings *1500

Please click on ads to support us..

Python Code:

n,w=map(int,input().split())
a=sorted(map(int,input().split()))
a1=a[0]
if a[0]*2>a[n]:a1=a[n]/2

if 2*a1*n+a1*n<w:
    print(2*a1*n+a1*n)
else:
    print(w)

C++ Code:

#include <algorithm>
#include <iostream>
#include <vector>

template <typename T>
std::istream& operator >>(std::istream& input, std::vector<T>& v)
{
    for (T& a : v)
        input >> a;

    return input;
}

void answer(double x)
{
    std::cout << std::fixed << x << '\n';
}

void solve(std::vector<unsigned>& a, unsigned w)
{
    const size_t n = a.size() / 2;

    std::sort(a.begin(), a.end());

    const double b = std::min<double>(a[0], a[n] / 2.0);
    answer(std::min<double>(3 * b * n, w));
}

int main()
{
    std::cin.tie(nullptr)->sync_with_stdio(false);

    size_t n;
    std::cin >> n;

    unsigned w;
    std::cin >> w;

    std::vector<unsigned> a(2 * n);
    std::cin >> a;

    solve(a, w);

    return 0;
}


Comments

Submit
0 Comments
More Questions

53A - Autocomplete
1729G - Cut Substrings
805B - 3-palindrome
805C - Find Amir
676C - Vasya and String
1042B - Vitamins
1729F - Kirei and the Linear Function
25D - Roads not only in Berland
1694A - Creep
659F - Polycarp and Hay
1040A - Palindrome Dance
372A - Counting Kangaroos is Fun
1396B - Stoned Game
16A - Flag
1056A - Determine Line
670B - Game of Robots
1418C - Mortal Kombat Tower
1382B - Sequential Nim
1272C - Yet Another Broken Keyboard
808A - Lucky Year
1245A - Good ol' Numbers Coloring
58B - Coins
1041C - Coffee Break
507A - Amr and Music
1041D - Glider
1486A - Shifting Stacks
1389B - Array Walk
71B - Progress Bar
701A - Cards
545A - Toy Cars